/**
 * 作者: wgx
 * 日期: 2024-10-17 11:34:37
 * 备注: 用户伙伴表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserPartner;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserPartnerModel extends BaseModel implements Model {
    public static final String LISTKEY = "user_id.partner_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 数据库ID
    protected long userId; // 用户ID
    protected int partnerId; // partner_id
    protected int level; // 等级
    protected int maxLevel; // 等级上限
    protected int star; // 升星阶数，5阶=1星
    protected int itemTalent; // 使用道具增加的资质
    protected int suitId; // 服装Id
    protected long itemPower; // 使用道具增加战力固定值
    protected long weaponDbid; // 装备的武器
    protected int breakNum; // 突破次数
    protected int buildId; // 委派到的建筑id
    protected long totalPower; // 总战力
    protected int weaponTalent; // 武器增加的基础资质 (取userweapon表的talent)
    protected int weaponAdd2; // 武器增加的战力百分比
    protected long skillAdd; // 干员技能增加的固定值
    protected int skillAdd2; // 干员技能增加的百分比(1W倍)
    protected long secrAdd; // 秘书羁绊技能增加的固定值
    protected int secrAdd2; // 秘书羁绊技能增加的百分比(放到1W倍)
    protected long snatchAdd; // 物资争夺挑战胜利的战力加成
    protected long basePower; // 基础战力 (总资质 * 资质提升系数)
    protected String skillBaseLevel = ""; // 干员基础技能的升级情况
    protected String skillWorldLevel = ""; // 干员大世界技能的升级情况
    protected String skillStarLevel = ""; // 升星解锁的技能的等级 (技能等级[0,1,1,0,0,0],0星，1星--5星)
    protected String skillHaloLevel = ""; // 光环技能的等级 (技能等级[0,0])

    public void reset() {
    }

    protected String getKey() {
        return "UserPartner." + userId + "." + partnerId;
    }

    protected String getListKey() {
        return "UserPartner." + userId;
    }

    protected String getListItemKey() {
        return partnerId + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_partner"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 数据库ID
        obj.put("userId", userId); // 用户ID
        obj.put("partnerId", partnerId); // partner_id
        obj.put("level", level); // 等级
        obj.put("maxLevel", maxLevel); // 等级上限
        obj.put("star", star); // 升星阶数，5阶=1星
        obj.put("itemTalent", itemTalent); // 使用道具增加的资质
        obj.put("suitId", suitId); // 服装Id
        obj.put("itemPower", itemPower); // 使用道具增加战力固定值
        obj.put("weaponDbid", weaponDbid); // 装备的武器
        obj.put("breakNum", breakNum); // 突破次数
        obj.put("buildId", buildId); // 委派到的建筑id
        obj.put("totalPower", totalPower); // 总战力
        obj.put("weaponTalent", weaponTalent); // 武器增加的基础资质 (取userweapon表的talent)
        obj.put("weaponAdd2", weaponAdd2); // 武器增加的战力百分比
        obj.put("skillAdd", skillAdd); // 干员技能增加的固定值
        obj.put("skillAdd2", skillAdd2); // 干员技能增加的百分比(1W倍)
        obj.put("secrAdd", secrAdd); // 秘书羁绊技能增加的固定值
        obj.put("secrAdd2", secrAdd2); // 秘书羁绊技能增加的百分比(放到1W倍)
        obj.put("snatchAdd", snatchAdd); // 物资争夺挑战胜利的战力加成
        obj.put("basePower", basePower); // 基础战力 (总资质 * 资质提升系数)
        obj.put("skillBaseLevel", skillBaseLevel); // 干员基础技能的升级情况
        obj.put("skillWorldLevel", skillWorldLevel); // 干员大世界技能的升级情况
        obj.put("skillStarLevel", skillStarLevel); // 升星解锁的技能的等级 (技能等级[0,1,1,0,0,0],0星，1星--5星)
        obj.put("skillHaloLevel", skillHaloLevel); // 光环技能的等级 (技能等级[0,0])
        return obj;
    }

    public PBUserPartner.Builder takeInitBuilder() {
        PBUserPartner.Builder sb = PBUserPartner.newBuilder();
        if (partnerId != 0) {
            sb.setPartnerId(partnerId);
        }
        if (level != 0) {
            sb.setLevel(level);
        }
        if (maxLevel != 0) {
            sb.setMaxLevel(maxLevel);
        }
        if (star != 0) {
            sb.setStar(star);
        }
        if (suitId != 0) {
            sb.setSuitId(suitId);
        }
        if (weaponDbid != 0) {
            sb.setWeaponDbid(weaponDbid);
        }
        if (buildId != 0) {
            sb.setBuildId(buildId);
        }
        if (totalPower != 0) {
            sb.setTotalPower(totalPower);
        }
        if (basePower != 0) {
            sb.setBasePower(basePower);
        }
        if (this.skillBaseLevel != null && this.skillBaseLevel.length() > 0) {
            JsonArray list = new JsonArray(this.skillBaseLevel);
            for(int i=0; i<list.size(); i++) {
                sb.addSkillBaseLevel(list.getInteger(i));
            }
        }
        if (this.skillWorldLevel != null && this.skillWorldLevel.length() > 0) {
            JsonArray list = new JsonArray(this.skillWorldLevel);
            for(int i=0; i<list.size(); i++) {
                sb.addSkillWorldLevel(list.getInteger(i));
            }
        }
        if (this.skillStarLevel != null && this.skillStarLevel.length() > 0) {
            JsonArray list = new JsonArray(this.skillStarLevel);
            for(int i=0; i<list.size(); i++) {
                sb.addSkillStarLevel(list.getInteger(i));
            }
        }
        if (this.skillHaloLevel != null && this.skillHaloLevel.length() > 0) {
            JsonArray list = new JsonArray(this.skillHaloLevel);
            for(int i=0; i<list.size(); i++) {
                sb.addSkillHaloLevel(list.getInteger(i));
            }
        }
        return sb;
    }

    public PBUserPartner.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserPartner.Builder sb = PBUserPartner.newBuilder();
        if (isFieldUpdate("partnerId")) {
            sb.setPartnerId(partnerId);
        }
        if (isFieldUpdate("level")) {
            sb.setLevel(level);
        }
        if (isFieldUpdate("maxLevel")) {
            sb.setMaxLevel(maxLevel);
        }
        if (isFieldUpdate("star")) {
            sb.setStar(star);
        }
        if (isFieldUpdate("suitId")) {
            sb.setSuitId(suitId);
        }
        if (isFieldUpdate("weaponDbid")) {
            sb.setWeaponDbid(weaponDbid);
        }
        if (isFieldUpdate("buildId")) {
            sb.setBuildId(buildId);
        }
        if (isFieldUpdate("totalPower")) {
            sb.setTotalPower(totalPower);
        }
        if (isFieldUpdate("basePower")) {
            sb.setBasePower(basePower);
        }
        if (isFieldUpdate("skillBaseLevel")) {
            if (this.skillBaseLevel != null && this.skillBaseLevel.length() > 0) {
                JsonArray list = new JsonArray(this.skillBaseLevel);
                for(int i=0; i<list.size(); i++) {
                    sb.addSkillBaseLevel(list.getInteger(i));
                }
                if (list.isEmpty()) {
                    sb.clearSkillBaseLevel();
                }
            } else {
                sb.clearSkillBaseLevel();
            }
        }
        if (isFieldUpdate("skillWorldLevel")) {
            if (this.skillWorldLevel != null && this.skillWorldLevel.length() > 0) {
                JsonArray list = new JsonArray(this.skillWorldLevel);
                for(int i=0; i<list.size(); i++) {
                    sb.addSkillWorldLevel(list.getInteger(i));
                }
                if (list.isEmpty()) {
                    sb.clearSkillWorldLevel();
                }
            } else {
                sb.clearSkillWorldLevel();
            }
        }
        if (isFieldUpdate("skillStarLevel")) {
            if (this.skillStarLevel != null && this.skillStarLevel.length() > 0) {
                JsonArray list = new JsonArray(this.skillStarLevel);
                for(int i=0; i<list.size(); i++) {
                    sb.addSkillStarLevel(list.getInteger(i));
                }
                if (list.isEmpty()) {
                    sb.clearSkillStarLevel();
                }
            } else {
                sb.clearSkillStarLevel();
            }
        }
        if (isFieldUpdate("skillHaloLevel")) {
            if (this.skillHaloLevel != null && this.skillHaloLevel.length() > 0) {
                JsonArray list = new JsonArray(this.skillHaloLevel);
                for(int i=0; i<list.size(); i++) {
                    sb.addSkillHaloLevel(list.getInteger(i));
                }
                if (list.isEmpty()) {
                    sb.clearSkillHaloLevel();
                }
            } else {
                sb.clearSkillHaloLevel();
            }
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public int getPartnerId() {
        return partnerId;
    }

    public void putPartnerId(int partnerId) {
        if (this.partnerId != partnerId) {
            this.partnerId = partnerId;
            updateRedisHashField(getKey(), "partnerId", this.partnerId);
        }
    }

    public void addPartnerId(int value) {
        this.partnerId += value;
        updateRedisHashField(getKey(), "partnerId", this.partnerId);
    }

    public int getLevel() {
        return level;
    }

    public void putLevel(int level) {
        if (this.level != level) {
            this.level = level;
            updateRedisHashField(getKey(), "level", this.level);
        }
    }

    public void addLevel(int value) {
        this.level += value;
        updateRedisHashField(getKey(), "level", this.level);
    }

    public int getMaxLevel() {
        return maxLevel;
    }

    public void putMaxLevel(int maxLevel) {
        if (this.maxLevel != maxLevel) {
            this.maxLevel = maxLevel;
            updateRedisHashField(getKey(), "maxLevel", this.maxLevel);
        }
    }

    public void addMaxLevel(int value) {
        this.maxLevel += value;
        updateRedisHashField(getKey(), "maxLevel", this.maxLevel);
    }

    public int getStar() {
        return star;
    }

    public void putStar(int star) {
        if (this.star != star) {
            this.star = star;
            updateRedisHashField(getKey(), "star", this.star);
        }
    }

    public void addStar(int value) {
        this.star += value;
        updateRedisHashField(getKey(), "star", this.star);
    }

    public int getItemTalent() {
        return itemTalent;
    }

    public void putItemTalent(int itemTalent) {
        if (this.itemTalent != itemTalent) {
            this.itemTalent = itemTalent;
            updateRedisHashField(getKey(), "itemTalent", this.itemTalent);
        }
    }

    public void addItemTalent(int value) {
        this.itemTalent += value;
        updateRedisHashField(getKey(), "itemTalent", this.itemTalent);
    }

    public int getSuitId() {
        return suitId;
    }

    public void putSuitId(int suitId) {
        if (this.suitId != suitId) {
            this.suitId = suitId;
            updateRedisHashField(getKey(), "suitId", this.suitId);
        }
    }

    public void addSuitId(int value) {
        this.suitId += value;
        updateRedisHashField(getKey(), "suitId", this.suitId);
    }

    public long getItemPower() {
        return itemPower;
    }

    public void putItemPower(long itemPower) {
        if (this.itemPower != itemPower) {
            this.itemPower = itemPower;
            updateRedisHashField(getKey(), "itemPower", this.itemPower);
        }
    }

    public void addItemPower(long value) {
        this.itemPower += value;
        updateRedisHashField(getKey(), "itemPower", this.itemPower);
    }

    public long getWeaponDbid() {
        return weaponDbid;
    }

    public void putWeaponDbid(long weaponDbid) {
        if (this.weaponDbid != weaponDbid) {
            this.weaponDbid = weaponDbid;
            updateRedisHashField(getKey(), "weaponDbid", this.weaponDbid);
        }
    }

    public void addWeaponDbid(long value) {
        this.weaponDbid += value;
        updateRedisHashField(getKey(), "weaponDbid", this.weaponDbid);
    }

    public int getBreakNum() {
        return breakNum;
    }

    public void putBreakNum(int breakNum) {
        if (this.breakNum != breakNum) {
            this.breakNum = breakNum;
            updateRedisHashField(getKey(), "breakNum", this.breakNum);
        }
    }

    public void addBreakNum(int value) {
        this.breakNum += value;
        updateRedisHashField(getKey(), "breakNum", this.breakNum);
    }

    public int getBuildId() {
        return buildId;
    }

    public void putBuildId(int buildId) {
        if (this.buildId != buildId) {
            this.buildId = buildId;
            updateRedisHashField(getKey(), "buildId", this.buildId);
        }
    }

    public void addBuildId(int value) {
        this.buildId += value;
        updateRedisHashField(getKey(), "buildId", this.buildId);
    }

    public long getTotalPower() {
        return totalPower;
    }

    public void putTotalPower(long totalPower) {
        if (this.totalPower != totalPower) {
            this.totalPower = totalPower;
            updateRedisHashField(getKey(), "totalPower", this.totalPower);
        }
    }

    public void addTotalPower(long value) {
        this.totalPower += value;
        updateRedisHashField(getKey(), "totalPower", this.totalPower);
    }

    public int getWeaponTalent() {
        return weaponTalent;
    }

    public void putWeaponTalent(int weaponTalent) {
        if (this.weaponTalent != weaponTalent) {
            this.weaponTalent = weaponTalent;
            updateRedisHashField(getKey(), "weaponTalent", this.weaponTalent);
        }
    }

    public void addWeaponTalent(int value) {
        this.weaponTalent += value;
        updateRedisHashField(getKey(), "weaponTalent", this.weaponTalent);
    }

    public int getWeaponAdd2() {
        return weaponAdd2;
    }

    public void putWeaponAdd2(int weaponAdd2) {
        if (this.weaponAdd2 != weaponAdd2) {
            this.weaponAdd2 = weaponAdd2;
            updateRedisHashField(getKey(), "weaponAdd2", this.weaponAdd2);
        }
    }

    public void addWeaponAdd2(int value) {
        this.weaponAdd2 += value;
        updateRedisHashField(getKey(), "weaponAdd2", this.weaponAdd2);
    }

    public long getSkillAdd() {
        return skillAdd;
    }

    public void putSkillAdd(long skillAdd) {
        if (this.skillAdd != skillAdd) {
            this.skillAdd = skillAdd;
            updateRedisHashField(getKey(), "skillAdd", this.skillAdd);
        }
    }

    public void addSkillAdd(long value) {
        this.skillAdd += value;
        updateRedisHashField(getKey(), "skillAdd", this.skillAdd);
    }

    public int getSkillAdd2() {
        return skillAdd2;
    }

    public void putSkillAdd2(int skillAdd2) {
        if (this.skillAdd2 != skillAdd2) {
            this.skillAdd2 = skillAdd2;
            updateRedisHashField(getKey(), "skillAdd2", this.skillAdd2);
        }
    }

    public void addSkillAdd2(int value) {
        this.skillAdd2 += value;
        updateRedisHashField(getKey(), "skillAdd2", this.skillAdd2);
    }

    public long getSecrAdd() {
        return secrAdd;
    }

    public void putSecrAdd(long secrAdd) {
        if (this.secrAdd != secrAdd) {
            this.secrAdd = secrAdd;
            updateRedisHashField(getKey(), "secrAdd", this.secrAdd);
        }
    }

    public void addSecrAdd(long value) {
        this.secrAdd += value;
        updateRedisHashField(getKey(), "secrAdd", this.secrAdd);
    }

    public int getSecrAdd2() {
        return secrAdd2;
    }

    public void putSecrAdd2(int secrAdd2) {
        if (this.secrAdd2 != secrAdd2) {
            this.secrAdd2 = secrAdd2;
            updateRedisHashField(getKey(), "secrAdd2", this.secrAdd2);
        }
    }

    public void addSecrAdd2(int value) {
        this.secrAdd2 += value;
        updateRedisHashField(getKey(), "secrAdd2", this.secrAdd2);
    }

    public long getSnatchAdd() {
        return snatchAdd;
    }

    public void putSnatchAdd(long snatchAdd) {
        if (this.snatchAdd != snatchAdd) {
            this.snatchAdd = snatchAdd;
            updateRedisHashField(getKey(), "snatchAdd", this.snatchAdd);
        }
    }

    public void addSnatchAdd(long value) {
        this.snatchAdd += value;
        updateRedisHashField(getKey(), "snatchAdd", this.snatchAdd);
    }

    public long getBasePower() {
        return basePower;
    }

    public void putBasePower(long basePower) {
        if (this.basePower != basePower) {
            this.basePower = basePower;
            updateRedisHashField(getKey(), "basePower", this.basePower);
        }
    }

    public void addBasePower(long value) {
        this.basePower += value;
        updateRedisHashField(getKey(), "basePower", this.basePower);
    }

    public JsonArray getSkillBaseLevelArray() {
        if (this.skillBaseLevel != null && this.skillBaseLevel.length() > 0) {
            return new JsonArray(this.skillBaseLevel);
        } else {
            return new JsonArray();
        }
    }

    public String getSkillBaseLevel() {
        return skillBaseLevel;
    }

    public void putSkillBaseLevel(String skillBaseLevel) {
        if (!this.skillBaseLevel.equals(skillBaseLevel)) {
            this.skillBaseLevel = skillBaseLevel;
            updateRedisHashField(getKey(), "skillBaseLevel", this.skillBaseLevel);
        }
    }

    public JsonArray getSkillWorldLevelArray() {
        if (this.skillWorldLevel != null && this.skillWorldLevel.length() > 0) {
            return new JsonArray(this.skillWorldLevel);
        } else {
            return new JsonArray();
        }
    }

    public String getSkillWorldLevel() {
        return skillWorldLevel;
    }

    public void putSkillWorldLevel(String skillWorldLevel) {
        if (!this.skillWorldLevel.equals(skillWorldLevel)) {
            this.skillWorldLevel = skillWorldLevel;
            updateRedisHashField(getKey(), "skillWorldLevel", this.skillWorldLevel);
        }
    }

    public JsonArray getSkillStarLevelArray() {
        if (this.skillStarLevel != null && this.skillStarLevel.length() > 0) {
            return new JsonArray(this.skillStarLevel);
        } else {
            return new JsonArray();
        }
    }

    public String getSkillStarLevel() {
        return skillStarLevel;
    }

    public void putSkillStarLevel(String skillStarLevel) {
        if (!this.skillStarLevel.equals(skillStarLevel)) {
            this.skillStarLevel = skillStarLevel;
            updateRedisHashField(getKey(), "skillStarLevel", this.skillStarLevel);
        }
    }

    public JsonArray getSkillHaloLevelArray() {
        if (this.skillHaloLevel != null && this.skillHaloLevel.length() > 0) {
            return new JsonArray(this.skillHaloLevel);
        } else {
            return new JsonArray();
        }
    }

    public String getSkillHaloLevel() {
        return skillHaloLevel;
    }

    public void putSkillHaloLevel(String skillHaloLevel) {
        if (!this.skillHaloLevel.equals(skillHaloLevel)) {
            this.skillHaloLevel = skillHaloLevel;
            updateRedisHashField(getKey(), "skillHaloLevel", this.skillHaloLevel);
        }
    }

}